Skip to content

refactor: extract shared logic from framework adapters to core#145

Merged
Nowely merged 9 commits intonextfrom
improves
Mar 7, 2026
Merged

refactor: extract shared logic from framework adapters to core#145
Nowely merged 9 commits intonextfrom
improves

Conversation

@Nowely
Copy link
Owner

@Nowely Nowely commented Mar 7, 2026

Summary

This PR refactors the codebase to reduce duplication between React and Vue adapters by moving shared logic to the core package. Key improvements include:

  • Slot resolution utilities: Introduces generic slot resolution utilities in core that both frameworks can use
  • Shared logic migration: Moves DEFAULT_OPTIONS, createMarkFromOverlay, DataAttributes type, and other shared utilities from framework adapters to @markput/core
  • Context improvements: Replaces TokenProvider with TokenContext for better context management and updates useStore to use StoreContext provider
  • Simplified renderers: Streamlines slot resolution in MarkRenderer and OverlayRenderer components with enhanced generic type support

Nowely added 8 commits March 7, 2026 16:25
…t management

## Summary
- Refactored the context management by replacing `TokenProvider` with `TokenContext` across multiple components.
- Updated imports and usage in `MarkedInput`, `MarkRenderer`, `TextSpan`, and `Token` components to utilize the new context.
- Removed the deprecated `TokenProvider` and associated utility functions.

## Changes
- Updated context provider usage in `MarkedInput.tsx`, `MarkRenderer.tsx`, `TextSpan.tsx`, and `Token.tsx`.
- Introduced `TokenContext.ts` for the new context implementation.
- Deleted `TokenProvider.ts` and `createContext.ts` as they are no longer needed.
## Summary
- Replaced imports of `useStore` from the deprecated `hooks` directory to the new `providers/StoreContext` across multiple components.
- Removed the old `useStore` hook implementation as it is now integrated within the `StoreContext`.

## Changes
- Updated imports in `BlockContainer`, `Container`, `MarkRenderer`, `OverlayRenderer`, `TextSpan`, `Suggestions`, `useMark`, `useOverlay`, and `useSlot` components.
- Deleted the `useStore.ts` file from the `hooks` directory.
- Enhanced `StoreContext.ts` to include a new `useStore` implementation with error handling.
## Summary
- Added new utility functions `resolveSlot` and `resolveSlotProps` to handle slot resolution in both React and Vue components.
- Updated existing components to utilize the new slot utilities, improving code organization and maintainability.
- Removed the old slot resolution implementation from the `utils` directory.

## Changes
- Created `slots.ts` in both React and Vue libraries to encapsulate slot resolution logic.
- Updated imports in `BlockContainer`, `Container`, and `TextSpan` components to use the new slot utilities.
- Enhanced type definitions for better TypeScript support.
## Summary
- Updated `resolveSlot` and `resolveSlotProps` functions to support generic types, improving type safety and flexibility in component implementations.
- Removed the old slot resolution implementation from the `lib/slots` directory in both React and Vue packages.
- Adjusted component imports and usages in `BlockContainer`, `Container`, and `TextSpan` to utilize the updated slot resolution utilities.

## Changes
- Enhanced type definitions for `resolveSlot` and `resolveSlotProps` to allow for more specific return types.
- Updated components to reflect the new generic type usage, ensuring better integration with TypeScript's type system.
…r components

## Summary
- Updated `MarkRenderer` and `OverlayRenderer` components to utilize the new `useSlot` utility for improved slot resolution.
- Removed unnecessary component references and streamlined the computed properties for better readability and maintainability.

## Changes
- Refactored the `resolved` computed property in both components to leverage the `useSlot` function, enhancing type safety and reducing complexity.
- Adjusted template bindings to align with the new slot resolution structure.
- Move DEFAULT_OPTIONS constant from React/Vue to @markput/core
- Create createMarkFromOverlay utility for token creation from overlay matches
- Remove duplicated constants.ts files from both framework packages
- Update useOverlay hooks to use new core utility
- Add MarkOptions interface to core
- Add resolveOptionSlot utility for slot resolution
- Add filterSuggestions for overlay filtering
- Add suggestionNavigation for keyboard navigation
- Update React/Vue adapters to use core utilities
@vercel
Copy link

vercel bot commented Mar 7, 2026

Deployment failed with the following error:

Resource is limited - try again in 3 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/nowelys-projects?upgradeToPro=build-rate-limit

@Nowely Nowely merged commit 795c0e8 into next Mar 7, 2026
6 of 9 checks passed
@Nowely Nowely deleted the improves branch March 7, 2026 15:00
Nowely pushed a commit that referenced this pull request Mar 7, 2026
🤖 I have created a release *beep* *boop*
---


## [0.5.0](0.4.0...0.5.0)
(2026-03-07)


### Features

* **core:** add ContentEditableController for DOM-based editing
([#134](#134))
([633133b](633133b))


### Refactoring

* extract shared logic from framework adapters to core
([#145](#145))
([795c0e8](795c0e8))
* improve Signal typing with interface augmentation for
framework-specific use() return types
([#143](#143))
([e6d4efc](e6d4efc))


### Miscellaneous

* migrate to pnpm catalog for centralized dependency management
([#140](#140))
([b71cd55](b71cd55))
* update oxlint configuration
([#144](#144))
([1db73ec](1db73ec))


### Tests

* add comprehensive Vue component tests with Vitest
([#142](#142))
([231f3dc](231f3dc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant